package Day05;

import java.util.Scanner;

public class ArrayDemo {
    public static void main(String[] args) {


        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }












//        int[] arr = new int[10];
//        for (int i=0;i<arr.length;i++){
//            arr[i] = (int)(Math.random()*100);
//            System.out.println("arr["+i+"]"+"="+arr[i]);
//        }
/*
        //4)数组的遍历：从头到尾挨个揍一遍
        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){//遍历每一个arr数组
            arr[i] = (int)(Math.random()*100);//给每个元素赋值为0-99之间的随机数
            System.out.println(arr[i]);//输出每个元素的值
        }
*/



//
//        Scanner scan = new Scanner(System.in);
//        System.out.println("请输入数组个数:");
//        int s = scan.nextInt();
//        int[] arr = new int[s];
//        for(int i=0;i<arr.length;i++){
//            arr[i] = (int)(Math.random()*100);
//            System.out.println("arr["+i+"]"+"="+arr[i]);
//        }
//


/*        int[] arr = new int[3];
        System.out.println(arr.length);
        System.out.println(arr[0]);
        arr[0] = 100;
        arr[1] = 200;
        arr[2] = 300;
        //arr[4] = 400;
        System.out.println(arr[arr.length-1]);*/








/*
        //3)数组的访问:访问的是数组中的元素
        int[] arr = new int[3];
        System.out.println(arr.length);   //输出arr的长度
        System.out.println(arr[0]);   //输出第一个元素的值
        arr[0] = 100;               //  给第一个元素赋为100
        arr[1] = 200;
        arr[2] = 300;
        System.out.println(arr[arr.length-1]);           //输出最后一个元素的值

*/

















/*        int[] arr = new int[10];
        int[] arr1 = new int[]{1,4,7};
        int[] arr2 = {1,4,7};
        int[] arr3;
        arr3 = new int[]{1,4,7};
        */



/*        int[] arr = new int[10];
        int[] arr1 = new int[]{1,4,7};
        int[] arr2 = {1,4,7};
        int[] arr4;
        arr4 = new int[]{1,4,7};*/


/*        int[] arr = new int[10];
        int[] arr1 = new int[3];
        int[] arr2 = new int[]{1,4,7};
        int[] arr3 = {1,4,7};
        int[] arr4;
        arr4 = new int[]{1,4,7};*/







/*        //1）数组的定义
        //声明一个整形的数组arr,包含10个元素，每个元素都是int型，默认值为0
        int[] arr = new int[10];

        //2)数组的初始化-----初始化的是数组中的数据
        int[] arr1 = new int[3];    //0,0,0
        int[] arr2 = {1,4,7};       //1,4,7
        int[] arr3 = new int[]{1,4,7};      //1,4,7
        int[] arr4;
        //arr4 = {1,4,7};         //编译错误，此方式只能声明同时初始化
        arr4 = new int[]{1,4,7};*/
    }
}
